package com.defines.ming.demo.controller;

import com.defines.ming.demo.model.EmpProjectList;
import com.defines.ming.demo.model.Result;
import com.defines.ming.demo.model.User;
import com.defines.ming.demo.service.UserMsgService;
import com.defines.ming.demo.utils.ApproveNode;
import com.defines.ming.demo.utils.FlowStatus;
import com.defines.ming.demo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    private UserMsgService userMsg;
    @PostMapping("/list")
    public Result list() {
        List<User> list = userMsg.getlist();
        return ResultUtil.success(list);
    }
    @PostMapping("/byID")
    public  Result listById(@RequestBody  Map<String,Object> map){
        System.out.println("lastName:"+map.get("lastName"));
        System.out.println("salary:"+map.get("salary"));
        List<User> list = userMsg.getListByEmpId(String.valueOf(map.get("lastName")),
                String.valueOf(map.get("salary")));
        System.out.println("ming:"+list.toString());
        return ResultUtil.success(list);
    }
    @PostMapping("/insertUser")
    public Result insertUser(@RequestBody User user){
        System.out.println(user.toString());
        userMsg.insertUser(user);
        return  ResultUtil.success(null);
    }
    @PostMapping("/myProjects")
    public Result getEmpProjectList(@RequestBody Map<String,Object> map){
        System.out.println("employeeCode:"+map.toString());
        List<EmpProjectList> list = userMsg.getEmpProjectList(String.valueOf(map.get("employeeCode")));
        return  ResultUtil.success(list);
    }
//    @PostMapping("/myProjects")
//    public Result getEmpProjectList(@RequestParam String employeeCode){
//        System.out.println("employeeCode:"+employeeCode);
//        List<EmpProjectList> list = userMsg.getEmpProjectList(String.valueOf(employeeCode));
//        return  ResultUtil.success(list);
//    }
    @RequestMapping("helloming")
    @ResponseBody
    public String say(){

        System.out.println(ApproveNode.getApproveNodeName(2).getNodeName());
        System.out.println(FlowStatus.getStatus(2).getStatus());
        return "hello world！hellominghellominspring boot postman调试ghelloming";
    }
}
